import React, { lazy, Suspense } from 'react'
import { useRoutes, Navigate } from 'react-router-dom';
import {
    AppstoreOutlined,
    ContainerOutlined,
    DesktopOutlined,
    MailOutlined,
    MenuFoldOutlined,
    MenuUnfoldOutlined,
    PieChartOutlined,
} from '@ant-design/icons';
// 引入loading 组件
import Loading from '@/components/Loading'
// 引入首页组件
const Home = lazy(() => import('@/views/layout/Home'))
// 账户管理
const Account = lazy(() => import('@/views/layout/account/Index'));
const Adminlist = lazy(() => import('@/views/layout/account/Adminlist'))
// 轮播图管理
const Banner = lazy(() => import('@/views/layout/banner/Index'));
const Bannerlist = lazy(() => import('@/views/layout/banner/Bannerlist'));
const Addbanner = lazy(() => import('@/views/layout/banner/Addbanner'))
// 产品管理
const Product = lazy(() => import('@/views/layout/product/Index'));
const Productlist = lazy(() => import('@/views/layout/product/Productlist'))
const Seckilllist = lazy(() => import('@/views/layout/product/Seckilllist'))
const Recommendlist = lazy(() => import('@/views/layout/product/Recommendlist'))
const Filterlist = lazy(() => import('@/views/layout/product/Filterlist'))
// 设置
const Setting = lazy(() => import('@/views/layout/setting/Index'));
const Systemset = lazy(() => import('@/views/layout/setting/Systemset'));
// 数据导入导出
const Exceloption = lazy(() => import('@/views/layout/dataoperation/Index'));
const Exportexcel = lazy(() => import('@/views/layout/dataoperation/Exportexcel'));
const Importexcel = lazy(() => import('@/views/layout/dataoperation/Importexcel'));

// 地图组件
const Map = lazy(() => import('@/views/layout/map/Index'))
const Baidumap = lazy(() => import('@/views/layout/map/Baidumap'))

// 404
const Notfind = lazy(() => import('@/views/Notfind'))
export const routes = [
    {
        path: '/home',
        element: <Home></Home>,
        label: '首页',
        key: '/home',
        icon: <AppstoreOutlined></AppstoreOutlined>,
        islink: true
    },
    {
        path: '/account',
        element: <Account></Account>,
        label: '账户管理',
        key: '/account',
        icon: <ContainerOutlined></ContainerOutlined>,
        children: [
            {
                path: '/account/adminlist',
                element: <Adminlist></Adminlist>,
                label: '管理员列表',
                key: '/account/adminlist',
                icon: <DesktopOutlined></DesktopOutlined>,
            }
        ]
    },
    {
        path: '/banner',
        element: <Banner></Banner>,
        label: '轮播图管理',
        key: '/banner',
        icon: <MailOutlined></MailOutlined>,
        children: [
            {
                path: '/banner/bannerlist',
                element: <Bannerlist></Bannerlist>,
                label: '轮播图列表',
                key: '/banner/bannerlist',
                icon: <MenuFoldOutlined></MenuFoldOutlined>,
            },
            {
                path: '/banner/addbanner',
                element: <Addbanner></Addbanner>,
                label: '添加轮播图'
            }
        ]
    },
    {
        path: '/product',
        element: <Product></Product>,
        key: '/product',
        label: '产品管理',
        icon: <MenuUnfoldOutlined></MenuUnfoldOutlined>,
        children: [
            {
                path: '/product/productlist',
                element: <Productlist></Productlist>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/product/productlist',
                label: '产品列表',
            },
            {
                path: '/product/filterlist',
                element: <Filterlist></Filterlist>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/product/filterlist',
                label: '筛选列表',
            },
            {
                path: '/product/seckilllist',
                element: <Seckilllist></Seckilllist>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/product/seckilllist',
                label: '秒杀列表',
            },
            {
                path: '/product/recommendlist',
                element: <Recommendlist></Recommendlist>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/product/recommendlist',
                label: '推荐列表',
            }
        ]
    },
    {
        path: '/exceloption',
        element: <Exceloption></Exceloption>,
        icon: <AppstoreOutlined></AppstoreOutlined>,
        key: '/exceloption',
        label: '数据导入导出',
        children: [
            {
                path: '/exceloption/exportexcel',
                element: <Exportexcel></Exportexcel>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/exceloption/exportexcel',
                label: '表格导出',
            },
            {
                path: '/exceloption/importexcel',
                element: <Importexcel></Importexcel>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/exceloption/importexcel',
                label: '表格导入',
            }
        ]
    },
    {
        path: '/map',
        element: <Map></Map>,
        icon: <AppstoreOutlined></AppstoreOutlined>,
        key: '/map',
        label: '地图',
        children: [
            {
                path: '/map/baidumap',
                element: <Baidumap></Baidumap>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/map/baidumap',
                label: '百度地图',
            }
        ]
    },
    {
        path: '/setting',
        element: <Setting></Setting>,
        icon: <AppstoreOutlined></AppstoreOutlined>,
        key: '/setting',
        label: '设置',
        children: [
            {
                path: '/setting/systemsetting',
                element: <Systemset></Systemset>,
                icon: <PieChartOutlined></PieChartOutlined>,
                key: '/setting/systemsetting',
                label: '系统设置',
            }
        ]
    },
    {
        path: '/',
        element: <Navigate to='/home'></Navigate>
    },
    {
        path: '*',
        element: <Notfind></Notfind>
    }
]
export default function Index() {
    const ele = useRoutes(routes);
    return (
        <Suspense fallback={<Loading tip='等待中...'></Loading>}>
            {ele}
        </Suspense>
    )
}
